db.define_table("templates",
    SQLField("title"),
    SQLField("content", 'text'),
    SQLField("tag", length=128, requires=IS_NOT_EMPTY()),
    SQLField("posted_on", 'datetime', default=request.now, writable=False),
    SQLField("posted_by", writable=False),
    SQLField("posted_id", 'integer', writable=False),
    )

db.templates.title.requires = [IS_NOT_EMPTY(), IS_NOT_IN_DB(db, 'templates.title')]
db.templates.content.requires = IS_NOT_EMPTY()
db.templates.tag.requires = IS_NOT_EMPTY()

if auth.is_logged_in():
    db.templates.posted_by.default=auth.user.first_name+' '+auth.user.last_name
    db.templates.posted_id.default=auth.user.id

